package routers

import (
	"github.com/gin-gonic/gin"
	"mall-api-gin/controllers"
	"mall-api-gin/middlewares"
)

func RouterInit(r *gin.Engine) *gin.Engine {
	r.GET("/index", controllers.IndexController{}.Index)
	GetApiRouter(r)
	return r
}

func GetApiRouter(r *gin.Engine) {
	apiRouter := r.Group("api")
	apiRouter.POST("password/login", controllers.PasswordController{}.Login)
	apiRouter.GET("captcha/get", controllers.PasswordController{}.Captcha)
	apiRouter.GET("captcha/verify", controllers.PasswordController{}.Verify)
	apiRouter.GET("sms/send", controllers.SmsController{}.Index)
	apiRouter.GET("sms/verify", controllers.SmsController{}.Verify)
	AuthToken(apiRouter)
	apiRouter.GET("user/index", controllers.UserController{}.Index)
	apiRouter.GET("password/parse_token", controllers.PasswordController{}.ParseToken)
}

func AuthToken(router *gin.RouterGroup) {
	router.Use(middlewares.JwtAuthMiddleware())
}
